package zero.tech.games.ddz.event;

import com.alibaba.fastjson.JSONObject;

import zero.tech.core.event.EventListener;
import zero.tech.core.event.EventType;
import zero.tech.games.ddz.data.DdzConfig;
import zero.tech.games.ddz.data.DdzGameBase;
import zero.tech.games.ddz.data.DdzRoomCache;
import zero.tech.games.ddz.data.DdzTimer;
import zero.tech.games.logic.common.Room;
import zero.tech.games.logic.data.LogicEventType;

public class RoomCreated implements EventListener{

	@Override
	public EventType netEventType() {
		return LogicEventType.ROOM_CREATED;
	}

	@Override
	public void notifyEvent(Object... objs) {
		Room room = (Room) objs[0];
		DdzTimer ddzTimer=new DdzTimer(room.getRoom_id());
		room.setTimer(ddzTimer);
		DdzRoomCache ddzRoomCache=new DdzRoomCache(room.getRoom_id());
		room.setRoomCache(ddzRoomCache);
		DdzGameBase ddzGameBase=new DdzGameBase(room.getRoom_id());
		room.setGameBase(ddzGameBase);
		DdzConfig ddzConfig=JSONObject.parseObject(room.getConfigStr(),DdzConfig.class);
		room.setGameConfig(ddzConfig);
	}

	@Override
	public boolean asynchronous() {
		return false;
	}

}
